import java.util.Arrays;

/**
 * @Author 12629
 * @Description：
 */
public class Test {
    public static void main(String[] args) {
       /* int[] array = {12,4,3,8,19,7};
        System.out.println(myToString(array));
        bubbleSort(array);
        //Arrays.sort(array,0,2);//[0,2)
        //System.out.println(Arrays.toString(array));
        System.out.println(myToString(array));*/
        /*int[] array2 = {};
        System.out.println(Arrays.toString(array2));*/


        /*int[] array3 = null;
        bubbleSort(array3);
*/
        int[] array = {12,4,3,8,19,7};
        reverse(array);
        System.out.println(myToString(array));
    }

    public static void reverse(int[] array) {
        if(array == null) {
            return;
        }
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            int tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            i++;
            j--;
        }
    }


    public static void bubbleSort(int[] array) {
        if(array == null) {
            return;
        }
        //i 代表的是趟数
        for (int i = 0; i < array.length-1; i++) {
            //已经是优化了 每次比上一次少1个
            boolean flg = false;//又一次优化
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j] > array[j+1]) {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = true;
                }
            }
            if(!flg) {
                //没有交换
                return;
            }
        }
    }



    public static String myToString(int[] array) {
        if(array == null) {
            return "null";
        }
        if(array.length == 0) {
            return "[]";
        }
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if(i != array.length-1) {
                ret += ", ";
            }
        }
        ret += "]";
        return ret;
    }

    public static void main9(String[] args) {
        int[] ret = func3();
        for (int i = 0; i < ret.length; i++) {
            System.out.println(ret[i]);
        }
    }


    public static int[] func3() {
        int[] ret = new int[2];
        ret[0] = 99;
        ret[1] = 199;
        return ret;
    }



    public static void main8(String[] args) {
        int[] array = {1,2,3,4};
        /*
            当我 分开调用func1和 func2
            func1();
            func2();
            array这个数组 里面的值 分别是多少？
            请以这样的方式回答：
            1.
            2.
         */
        func2(array);
        for (int x : array) {
            System.out.print(x+" ");
        }
        System.out.println();
    }
    public static void func1(int[] array) {
        array[0] = 99;
    }
    public static void func2(int[] array) {
        array = new int[]{11,22,33,44,55};
    }

    public static void main5(String[] args) {
        int[] array = null;
        System.out.println(array.length);
    }

    public static void main4(String[] args) {
        int[] array = {1,2,3,4};

        for (int i = 0; i < array.length; i++) {
           /* if(i == 2) {
                sdfsafsa
            }*/
            System.out.print(array[i]+" ");
        }
        System.out.println();

        //int count = 0;
        //增强for循环  for-each
        for (int x : array) {
            System.out.print(x+" ");
        }
        System.out.println();


    }


    public static void main3(String[] args) {
        int[] array = null;//局部变量
        System.out.println(array);
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4};
        System.out.println(array.length);


        int n = 10;
        int[] array3 = new int[n];

        array3[5] = 99;

        array3[6] = 88;

        /*System.out.println(array[0]);
        System.out.println(array[1]);
        System.out.println(array[2]);
        System.out.println(array[3]);*/
    }

    public static void main1(String[] args) {
        int[] array = {1,2,3,4};
        // int array2[] = {1,2,3,4}; 不建议这样的写法

        int[] array2 = new int[]{1,2,3,4};

        int[] array3 = new int[10];

    }




    public static int fib2(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 1;
        for (int i = 3; i <= n; i++) {
            f3 = f1+f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }


    public static int fib(int n) {
        if(n == 1) {
            return 0;
        }
        if(n == 2) {
            return 1;
        }

        return fib(n-1)+fib(n-2);
    }

    public static int add(int n) {
        if(n < 10) {
            return n;
        }
        return n%10+add(n/10);
    }


    public static int sum(int n) {
        if(n == 1) {
            return 1;
        }
        return n + sum(n-1);
    }

    public static void print(int n) {
        if(n < 10) {
            System.out.println(n%10);
            return;
        }
        //123
        print(n/10);
        System.out.println(n%10);
    }


    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        int tmp = n * fac(n-1);
        return tmp;
    }

    public static void func(int a){
        if(a == 1) {
            return;
        }
        System.out.println(a);
        func(a-1);
    }


    public static int max(int a,int b) {
        return a > b ? a:b;
    }
    public static int max(int a,int b,int c) {
        /*int ret = max2(a,b);
        return max2(ret,c);*/
        return max(max(a,b),c);
    }



}
